#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* Findparentpath(char* );
int searchnarray(char* );
char* foldernamefrompath(char* path);

int main()
{    char temppath[100];
    char intmpath[10][100];
    int i=0;
    strcpy(temppath, "/pqr/www/s1/s2/s3/s4/s5");
    int result= searchnarray(temppath);
    while(result==0)
        {
            result=searchnarray(temppath);
            if(result==0)
                {
                    strcpy(intmpath[i],temppath);
                    i++;
                }
            strcpy(temppath, Findparentpath(temppath));
            if(!strcmp(temppath,""))
            result=1;
        }

    for(i--;i>=0; i--)
        {
            //prin: %s \n",  intmpath[i]);
            printf("\n mkdir call to be generated for parent Path = %s and ",Findparentpath(intmpath[i]) );
            printf("foldername = %s \n ", foldernamefrompath(intmpath[i]));
        }
    return 0;

}

char* Findparentpath(char* path)
{    //printf("\n Findparentpath called\n");    
    int pathlength=0;
    char* temppath=(char*)malloc(100*sizeof(char));
    strcpy(temppath,path);
    while(*(path)!='\0')
        {   
            pathlength++;
            path++;
        }    
    while(temppath[pathlength]!='/')
        {
            temppath[pathlength]='\0';
            pathlength--;
        }
    temppath[pathlength]='\0';
    if(!strcmp(temppath,""))
        strcpy(temppath,"/");
    return temppath;
        
}

int searchnarray(char* path )
{
    if(!strcmp(path,"/"))
        return 1;
    else 
        return 0;
}

char* foldernamefrompath(char* path)
{    //printf("\n foldernamefrompath called\n");    
    int i=0,pathlength=0;
    char* temppath=(char*)malloc(100*sizeof(char));
    char* foldername=(char*)malloc(11*sizeof(char));
    strcpy(temppath,path);
    while(*(path)!='\0')
        {   
            pathlength++;
            path++;
        }    
    while(temppath[pathlength]!='/')
            pathlength--;
    pathlength++;
    while(temppath[pathlength]!='\0')
        {    foldername[i]=temppath[pathlength];
            i++;pathlength++;
        }
        
    foldername[i]='\0';
    return foldername;
        
}